﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Microhard.WeixinMP.Models;
using Microhard.WeixinMP.Msg;

namespace Microhard.WeixinMP.Validators
{
    public class WXMPAccountModelValidator : AbstractValidator<WXMPAccountModel>
    {
        public WXMPAccountModelValidator()
        {
            RuleSet("Insert", () =>
            {
                RuleFor(u => u.UserName).NotEmpty().WithMessage(MPAccountMsg.NeedUserName).When(r => r.WXMPID == Guid.Empty);
                RuleFor(u => u.Password).NotEmpty().WithMessage(MPAccountMsg.NeedPWD).When(r => r.WXMPID == Guid.Empty);

                RuleFor(u => u.AppID).NotEmpty().WithMessage(MPAccountMsg.NeedAppID).When(r => r.WXMPID == Guid.Empty);
                RuleFor(u => u.AppSecret).NotEmpty().WithMessage(MPAccountMsg.NeedAppSecret).When(r => r.WXMPID == Guid.Empty);
                RuleFor(u => u.CompanyID).NotEmpty().WithMessage(MPAccountMsg.NeedCompanyID).When(r => r.WXMPID == Guid.Empty);
                RuleFor(u => u.CompanyName).NotEmpty().WithMessage(MPAccountMsg.NeedCompanyName).When(r => r.WXMPID == Guid.Empty);
                RuleFor(u => u.Welcome).NotEmpty().WithMessage(MPAccountMsg.NeedWelcome).When(r => r.WXMPID == Guid.Empty);
            });
            RuleSet("Update", () =>
            {
                RuleFor(u => u.UserName).NotEmpty().WithMessage(MPAccountMsg.NeedUserName);
                RuleFor(u => u.Password).NotEmpty().WithMessage(MPAccountMsg.NeedPWD);

                RuleFor(u => u.AppID).NotEmpty().WithMessage(MPAccountMsg.NeedAppID);
                RuleFor(u => u.AppSecret).NotEmpty().WithMessage(MPAccountMsg.NeedAppSecret);
                RuleFor(u => u.CompanyID).NotEmpty().WithMessage(MPAccountMsg.NeedCompanyID);
                RuleFor(u => u.CompanyName).NotEmpty().WithMessage(MPAccountMsg.NeedCompanyName);
                RuleFor(u => u.Welcome).NotEmpty().WithMessage(MPAccountMsg.NeedWelcome);
            });
        }
    }
}
